<template>
  <scroll-view
    v-if="Object.values(data).length"
    scroll-y="true"
    class="content"
  >
    <uni-section title="产品信息" type="line">
      <uni-card :title="data.spareName" class="card">
        <text class="card-item" v-for="(i, z) in columns" :key="z"
          >{{ i.name }}：{{ data[i.field] }}</text
        >
      </uni-card>
    </uni-section>
    <uni-section title="库存信息" type="line">
      <uni-table border stripe emptyText="暂无更多数据">
        <uni-tr class="uni-table-head">
          <uni-th width="50" align="center">序号</uni-th>
          <uni-th width="150" align="center">所属厂区</uni-th>
          <uni-th width="150" align="center">库存量</uni-th>
        </uni-tr>
        <uni-tr v-for="(item, index) in tableData" :key="index">
          <uni-td align="center">{{ index + 1 }}</uni-td>
          <uni-td align="center">{{ item.companyName }}</uni-td>
          <uni-td align="center">{{ item.stockCount }}</uni-td>
        </uni-tr>
      </uni-table>
    </uni-section>

    <!-- <uni-section
        v-if="dataOne?.attachmentList?.length"
        title="附件信息"
        type="line"
      >
        <uni-list>
          <uni-list-item
            ellipsis="1"
            v-for="(i, z) in dataOne?.attachmentList"
            :key="z"
            :title="i.attachmentName"
          >
            <template v-slot:footer>
              <text
                class="download"
                @click="downloadFile(`${baseUrl}${i?.attachmentPath}`)"
                >查看</text
              >
            </template>
          </uni-list-item>
        </uni-list>
      </uni-section>
     -->
     <view class="action-number">
      <view class="title">申请数量（个）</view>
				<input class="text-center" v-model="number" type="number"   placeholder="请输入" />
    </view>
    <view class="action">
      <button class="color-ok"  @click="edit">
        <text>确认编辑</text>
      </button>
    </view>
  </scroll-view>

  <view v-else class="no-data"> 暂无数据 </view>
</template>
  
  <script>
import { TOKEN } from "@/utils/auth";
import { downloadFile } from "@/utils/download";
import { baseUrl } from "@/utils/httpInterceptor";
import { Toast } from "@/utils/uniHooks/toast";
import request from "@/utils/httpInterceptor";

export default {
  data() {
    return {
      data: {}, 
      columns: [],
      tableData: [],
      // dataOne: {},
      number:'',
      // baseUrl,
      // loading: false,
    };
  },

  computed: {},
  onLoad: function (option) {
    uni.showLoading({
      title: "加载中",
    });
    uni.setNavigationBarTitle({
      title: option?.billTypeName || "详情",
    });

    this.data = JSON.parse(option.itemData);
    this.columns = this.data._columns_;
    this.getTableData();
  },

  methods: {
    // Toast,
    // // 移除某个文件
    // clear(name) {
    //   // name=指定文件名，不传name默认移除所有文件
    //   delete this.files[name];
    //   this.$forceUpdate();
    // },

    // progress(item) {
    //   // 更新当前状态变化的文件

    //   this.files[item.name] = item;
    //   this.$forceUpdate();
    // },
    // dialogShow(v) {
    //   this.$refs.alertDialog.open();
    //   this.approveType = v;
    // },

    // downloadFile,
    // showimg(v) {
    //   uni.previewImage({
    //     urls: [v],
    //     longPressActions: {
    //       itemList: ["保存图片"],
    //       success: function (data) {
    //         downloadFile(v);
    //       },
    //       fail: function (err) {
    //         console.log(err.errMsg);
    //       },
    //     },
    //   });
    // },

    async edit() {
      if(!this.number) return Toast('请输入数量')
      const res = await request({
        url: `/spare/spare-purchase-apply-bill/edit/item`,
        method: "POST",
        data:
          {id:this.data.applyBillItemId,applyCount:Number(this.number)}
        
      });
      if (res?.code==='0') {
       Toast('修改成功')
      }
    },

    async getTableData() {
      const res = await request({
        url: `/spare/stock/general/company/summary-list/${this.data.spareId}`,
        method: "GET",
      });
      if (res?.data?.length) {
        this.tableData = res.data;
      }
    },
  },

};
</script>
  
  <style lang="scss" scoped>

  .action-number{
    padding:0 10px ;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    position: fixed;
    bottom: 45px;
    width: 100%;
    border-top: 1px solid #eee;
    height: 35px;
    align-items: center;
  }
</style>
  